feat(saved-queries): import and export JSON backups - #756
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
The initial CI run found a real regression in this PR: constructing the newly browser-loaded Zod object probes Fixed in 8733479 by enabling Zod's JIT-free mode before constructing the schema. No security-header or E2E assertion was changed. A fresh-process unit regression blocks and counts dynamic evaluation across module import and parsing: the previous commit attempts it once; this commit attempts it zero times and preserves the query metadata and Date values. All 21 targeted importer/storage tests, static checks and both builds pass. The existing browser CSP tests will verify the submitted fix in CI. |
cevheri
left a comment
There was a problem hiding this comment.
Both of #690's items are met, and the best thing in this PR is the test nobody asked you for.
plan-draft-boundary.test.ts in this repo exists because zod v4's eval probe took a CSP violation on every page rendering an agent run, and its docstring records that nothing caught it until an end-to-end run in a real browser did, with six local gates and twenty CI checks all passing. Your fresh-process test, replacing Function with a proxy that throws the way a strict script-src does and asserting zero probes, turns that into a unit test. I checked it bites: removing the z.config line turns it red.
I verified the fix rather than trusting it, because that docstring says the probe happens at module load, which would put your config too late. It is not true of 4.5.4. Counting new Function constructions: importing zod alone is 0, building the schema is 1, the first parse is 2, and with jitless it stays 0 through all three. zod's own source now short-circuits the probe under jitless with a comment about strict CSPs. So your commit message is right and the repo's comment is stale. That correction is mine, not yours, and I will make it.
Also refuted a concern of my own before raising it: there is no export-then-import gap on connectionType, because SHIPPED_DATABASE_TYPES derives from a Readonly<Record<DatabaseType, true>> and the compiler guarantees it covers every type.
One change. expect(input.value).toBe("") at SavedQueries.test.tsx:98 cannot fail. importFile sets only files, so a jsdom file input reads "" before your component does anything. Measured: delete event.target.value = "" from the source and all 18 cases still pass. The line is guarding something real, since picking the same file twice fires no change event, so a user who edits the JSON after a collision report and re-picks it gets silence. Please make the assertion observe the assignment instead, for example by defining a value setter on the input before firing and asserting it received "". I wrote that version to price it: 18 pass with your line in place, 1 fails without it.
Everything else measures clean: 14 unit, 33 storage and 18 component cases pass, all twenty checks green including E2E, and four of the five mutants I tried are killed, the survivor being the one above.
|
Updated in 96b264b. The import case now installs a setter spy on the file input and asserts that it receives
|
|
This is done. Merging shortly. The assertion bites now: 18 pass with Two things I checked beyond the ask. Your source is byte-identical to 8733479, so the CSP property is still the one E2E already verified green in a real browser on that head, and the coverage gate cannot move because nothing under Thanks for the note in your comment saying you restored the source byte-for-byte after running the control. That is the part of a report I can actually check, and it checked out. |
Description
Saved Queries now offers JSON export and import. Export writes the complete library even while a search or connection-type filter is active. Import validates the entire file before writing, merges new IDs, and reports collisions while preserving existing queries.
Closes #690.
Type of Change
Changes Made
downloadTextandjsonTextfor the JSON array backup. Preserve query text, engine, descriptions, tags and both timestamps.Testing
bun run test:components --pass-with-no-tests -t 'SavedQueries': 18 matching tests passed, 0 failed, including the reviewed file-input reset assertion.valuesetter receiving an empty string. Removing the reset assignment makes that case fail; the production source was restored byte-for-byte afterward.bun run test:unit --isolate --pass-with-no-tests -t 'parseSavedQueries|storage: saved queries': 21 passed, 0 failed.format,lint,typecheck,knip,readme:check,chart:check,channels:showcase:check,security:check, productionbuild,build:libandattw.bun run test/ coverage and E2E were not completed: this Windows host lacks Helm/chart dependencies, Docker is unavailable, and existing SQLite cleanup tests encounter Windows file-lock errors. Official Linux CI must verify the full suite and 100% line-coverage gate.Environment: Windows, Node.js 24.18.1, Bun 1.4.2. Builds used a clean checkout with real local dependencies; the latest follow-up changes only the component test.
Checklist
Additional Notes
AI-assisted implementation and test execution using Codex. No new dependencies or provider/schema changes. Import is additive: an ID collision is reported and skipped, never overwritten.